package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: BaseTrademarkController
 * Package: com.atguigu.gmall.product.controller
 * Description:
 *
 * @Author: cqk
 * @Create: 2023/10/19 - 15:03
 * @Version: v1.0
 */
@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTrademarkController {

    @Autowired
    private BaseTrademarkService baseTrademarkService;

    /**
     * 品牌分页列表查询
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/{page}/{size}")
    public Result getTrademarkPage(@PathVariable Long page,
                                   @PathVariable Long size){

        Page<BaseTrademark> baseTrademarkPage = new Page<>(page,size);

        IPage<BaseTrademark> baseTrademarkIPage = baseTrademarkService.getTrademarkPage(baseTrademarkPage);


        return Result.ok(baseTrademarkIPage);
    }

    /**
     * 增加baseTrademark
     * @param baseTrademark
     * @return
     */
    @PostMapping("/save")
    public Result save(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }

    /**
     * 更新baseTrademark
     * @param baseTrademark
     * @return
     */
    @PutMapping("/update")
    public Result update(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }

    /**
     * 回显数据
     * @param id
     * @return
     */
    @GetMapping("/get/{id}")
    public Result get(@PathVariable Long id){
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);

        return Result.ok(baseTrademark);

    }

    /**
     * 根据id删除baseTrademark
     * @param id
     * @return
     */
    @DeleteMapping("/remove/{id}")
    public Result delete(@PathVariable Long id){
        baseTrademarkService.removeById(id);

        return  Result.ok();
    }
}
